﻿using DFGK_WMS.IRepository;
using DFGK_WMS.Model.Models;
using DFGK_WMS.WebAPI.Controllers.Result;
using Microsoft.AspNetCore.Mvc;

namespace DFGK_WMS.WebAPI.Controllers.基础数据
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UnitRulesController : ControllerBase
    {
        private readonly IUnitRulesRepository unitRulesRepository;
        public UnitRulesController(IUnitRulesRepository unitRulesRepository)
        {
            this.unitRulesRepository = unitRulesRepository;
        }

        /// <summary>
        /// 添加计量单位换算规则
        /// </summary>
        /// <param name="warningRules"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult AddUnitRules(UnitOfMeasurementRules unitRules)
        {
            var IsOk = unitRulesRepository.AddUnitRules(unitRules);
            if (IsOk)
            {
                return Ok(BaseResult.Result(IsOk,"添加成功！", "200"));

            }
            return Ok(BaseResult.Result(false,"添加失败！", "500"));
        }

        /// <summary>
        /// 删除计量单位换算规则
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public IActionResult DelUnitRules(int id)
        {
            var IsOk = unitRulesRepository.DelUnitRules(id);
            if (IsOk)
            {
                return Ok(BaseResult.Result(IsOk,"删除成功！", "200"));

            }
            return Ok(BaseResult.Result(false,"删除失败！", "500"));
        }

        /// <summary>
        /// 修改计量单位换算规则
        /// </summary>
        /// <param name="warningRules"></param>
        /// <returns></returns>
        [HttpPut]
        public IActionResult UpdUnitRules(UnitOfMeasurementRules unitRules)
        {
            var IsOk = unitRulesRepository.UpdUnitRules(unitRules);
            if (IsOk)
            {
                return Ok(BaseResult.Result(IsOk,"修改成功！", "200"));

            }
            return Ok(BaseResult.Result(false,"删除失败！", "500"));
        }

        /// <summary>
        /// 查询计量单位换算规则
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetUnitRules(int id)
        {
            var list = unitRulesRepository.GetUnitRules(id);
            if (list != null)
            {
                return Ok(BaseResult.Result(list, "查询成功！", "200"));

            }
            return Ok(BaseResult.Result(null, "查询失败！", "500"));
        }

        /// <summary>
        /// 查询计量单位换算规则
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetUnitRulesList(int pageIndex, int pageSize)
        {
            var list = unitRulesRepository.GetUnitRulesList(pageIndex, pageSize);
            if (list != null)
            {
                return Ok(BaseResult.Result(list, "查询成功！", "200"));

            }
            return Ok(BaseResult.Result(null, "查询失败！", "500"));
        }

    }
}
